package ru.amse.stroganova.graph;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * 
 * This class provides a simple implementation of a graph vertex, applicable for
 * both directed and undirected graphs.
 * 
 * @author Dasha Stroganova
 * 
 */
public class Vertex {

	private final Set<Edge> outgoingEdges;

	private final Set<Edge> incomingEdges;

	/**
	 * Creates an isolated vertex.
	 * 
	 */
	public Vertex() {
		outgoingEdges = new HashSet<Edge>();
		incomingEdges = new HashSet<Edge>();
	}

	/**
	 * This method returns a set of leaving edges for directed graph and
	 * incident edges for undirected graph.
	 * 
	 * @return an unmodifiable set of outgoing edges.
	 */
	public Set<Edge> getOutgoingEdges() {
		return Collections.unmodifiableSet(outgoingEdges);
	}

	/**
	 * This method returns a set of entering edges for directed graph and an
	 * empty set for undirected graph.
	 * 
	 * @return an unmodifiable set of outgoing edges.
	 */
	public Set<Edge> getIncomingEdges() {
		return Collections.unmodifiableSet(incomingEdges);
	}
	
	void removeEdges() {
		outgoingEdges.clear();
		incomingEdges.clear();
	}

	void addOutgoingEdge(Edge edge) {
		outgoingEdges.add(edge);
	}

	void removeOutgoingEdge(Edge edge) {
		outgoingEdges.remove(edge);
	}

	void addIncomingEdge(Edge edge) {
		incomingEdges.add(edge);
	}

	void removeIncomingEdge(Edge edge) {
		incomingEdges.remove(edge);
	}
}
